package com.txunda.zhuohired.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.Pickers;
import com.txunda.zhuohired.bean.user.resume.EducationExperienceBean;
import com.txunda.zhuohired.view.PickerScrollView;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2017/11/11 11:48
 * 功能描述：期望行业
 * 联系方式：jiahuanchen@126.com
 */

public class EducationDialog extends Dialog implements View.OnClickListener {
    private EducationListener educationListener;
    private PickerScrollView picker_scroll_view_education;
    private Context context;
    private List<Pickers> list; // 滚动选择器数据
    private List<EducationExperienceBean.DataBean> educationExperienceList;

    private String industry = "";
    private String industry_id = "";


    public EducationDialog(Context context, List<EducationExperienceBean.DataBean> educationExperienceList,
                           EducationListener educationListener) {
        super(context, R.style.dialog_style);
        this.context = context;
        this.educationListener = educationListener;
        this.educationExperienceList = educationExperienceList;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_education);
        picker_scroll_view_education = findViewById(R.id.picker_scroll_view_education);
        findViewById(R.id.tv_dialog_education_close).setOnClickListener(this);
        findViewById(R.id.tv_dialog_education_cancel).setOnClickListener(this);
        findViewById(R.id.tv_dialog_education_sure).setOnClickListener(this);
        list = new ArrayList<>();
        for (int i = 0; i < educationExperienceList.size(); i++) {
            list.add(new Pickers(educationExperienceList.get(i).getEducation_name(), educationExperienceList.get(i)
                    .getId()));
        }
        // 设置数据，默认选择第一条
        picker_scroll_view_education.setData(list);
        picker_scroll_view_education.setSelected(0);
        picker_scroll_view_education.setOnSelectListener(pickerListener);
    }

    // 滚动选择器选中事件
    PickerScrollView.onSelectListener pickerListener = new PickerScrollView.onSelectListener() {

        @Override
        public void onSelect(Pickers pickers) {
            System.out.println("选择：" + pickers.getShowId() + "--银行："
                    + pickers.getShowConetnt());
            industry = pickers.getShowConetnt();
            industry_id = pickers.getShowId();
        }
    };

    @Override
    public void onClick(View view) {
        this.dismiss();
        switch (view.getId()) {
            case R.id.tv_dialog_education_sure://确认
                if (TextUtils.isEmpty(industry)) {
                    industry = educationExperienceList.get(0).getEducation_name();
                    industry_id = educationExperienceList.get(0).getId();
                    educationListener.onEducation(industry, industry_id);
                } else {
                    educationListener.onEducation(industry, industry_id);
                }
                break;
        }
    }

    public interface EducationListener {
        void onEducation(String type, String industry_id);
        //        void onSelectStation(String station, String content, String ask, String id);
    }
}
